<template>
	<Container>
		<view class="header">
			<image class="image img" :src="assignment.comparedArticle.imageUrl" mode="aspectFit"></image>
			<AudioIcon @iconTap="iconTap" :questionPress="questionPress" />
		</view>
		<Question :question="assignment.questionName"  />
		<Record ref="audio" @recordFinish="recordFinish" :isStart="!isStart" :answerText="assignment.answerTexts" :typeCode="assignment.typeCode" />
	</Container>
</template>

<script>
import { mixins } from '../../../common/mixins/assignmentDefault.js'
import AudioIcon from '../audioIcon.vue'
import Question from '../questionName.vue'
import Container from '../container.vue'
import Record from '../record.vue'
export default {
	mixins: [mixins],
	components: { AudioIcon, Question, Container, Record },
	data() {
		return {
			isStart: false
		}
	},
	watch: {
		questionPress: function(bool) {
			if (!bool && !this.isStart) {
				this.comparedPlay()
			}
		}
	},
	methods: {
		comparedPlay: async function() {
			this.dialogueAudio({
				src: this.assignment.comparedArticle.backgroundAudioUrl,
				speaker: this.assignment.comparedArticle.speaker,
				start: () => {
					this.questionPress = true
					const timer = setTimeout(async () => {
						const data = await this.parseTextAudio({
							text: this.assignment.comparedArticle.audioText
						})
						this.narratorAudio({
							src: data
						})
					}, this.assignment.comparedArticle.audioDelayMs)
				},
				end: async () => {
					this.isStart = true
					this.questionPress = false
				}
			})
		}
	}
}
</script>

<style scoped lang="stylus">
.header
	height 50vh
	width 720rpx
	max-width 65vh
	border-radius 70rpx
	border 12rpx solid #FCC77D
	background white
	box-sizing border-box
	margin 5vh 0
	display flex
	justify-content center
	align-items center
	position relative
	.image
		width 65%
		height 65%
</style>
